package com.gitee.Transformation

import org.apache.flink.api.scala.{DataSet, ExecutionEnvironment}
import org.apache.flink.api.scala._
import scala.collection.mutable
import scala.util.Random
//注意:
// min会返回最小的数据
// minBy会返回最小的数据所在的一整条数据
object MinAndMinByTest {
  def main(args: Array[String]): Unit = {
    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
    val scores = new mutable.MutableList[(Int, String, Double)]
    scores.+=((1, "yuwen", 90.0))
    scores.+=((2, "shuxue", 20.0))
    scores.+=((3, "yingyu", 30.0))
    scores.+=((4, "wuli", 40.0))
    scores.+=((5, "yuwen", 50.0))
    scores.+=((6, "wuli", 60.0))
    scores.+=((7, "yuwen", 70.0))
    val input: DataSet[(Int, String, Double)] = env.fromCollection(Random.shuffle(scores))

    //求每个学科下的最小分数
    input.groupBy(1).min(2).print() // 错误 (6, "wuli", 40.0)
    println("--------------")
    input.groupBy(1).minBy(2).print() // 准确 (4, "wuli", 40.0)
  }

}
